<?php
namespace Admin\Controller;
use Think\Controller;
class AnimalListController extends CommonController{

	public function list(){

		if ($type == 1) 
		{
			$where['date_y']=date('Y');
		}

		if ($type == 2) 
		{
			$where['date_h']=date('h');
		}

		if ($type == 3) 
		{
			$where['date_d']=date('d');
		}

		$data = M('animal_log')->where($where)->select();

		foreach ($data as $k => $v) {

			$arr [] = $v['num'];
		}

		$data['sum'] = array_sum($arr);

		dump($data);exit();
	}

	public function getW(){
		
	}

	public function animalLog(){
		$arr=array(

			'd_id' =>1,
			'animal'=>array(array('id'=>1,'num'=>2),array('id'=>2,'num'=>2),array('id'=>3,'num'=>3)),
			);

		$id = $arr['d_id'];

		foreach ($arr['animal'] as $k => $v) {

			$list[$k]['animal_id'] = $v['id'];
			$list[$k]['num']       = $v['num'];
			$list[$k]['device_id'] = $id;

			$list[$k]['date_y']    = date('Y');
			$list[$k]['date_m']    = date('m');
			$list[$k]['date_d']    = date('d');

			$list[$k]['date_h']    = date('H');
			$list[$k]['add_time']  = time();

		}
		
		$data=M('animal_log')->addAll($list);

		dump($data);exit();
	}
}